View Javadoc

1   
2   /*
3    * SmartCrawler
4    *
5    * $Id: DefaultLinkFilter.java,v 1.6 2005/08/05 13:51:00 vincool Exp $
6    * Copyright 2005 Davide Pozza
7    *
8    * This program is free software; you can redistribute it
9    * and/or modify it under the terms of the GNU General Public
10   * License as published by the Free Software Foundation;
11   * either version 2 of the License, or (at your option) any
12   * later version.
13   *
14   * This program is distributed in the hope that it will be
15   * useful, but WITHOUT ANY WARRANTY; without even the implied
16   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17   * PURPOSE. See the GNU General Public License for more
18   * details.
19   *
20   * You should have received a copy of the GNU General Public
21   * License along with this program; if not, write to the Free
22   * Software Foundation, Inc., 59 Temple Place, Suite 330,
23   * Boston, MA 02111-1307 USA
24   *
25   */
26  
27  package org.smartcrawler.filter;
28  import org.apache.log4j.Logger;
29  import org.smartcrawler.common.Context;
30  import org.smartcrawler.common.Link;
31  import org.smartcrawler.common.SCLogger;
32  
33  
34  /***
35   *
36   *
37   * @author <a href="mailto:pozzad@alice.it">Davide Pozza</a>
38   * @version <tt>$Revision: 1.6 $</tt>
39   */
40  public class DefaultLinkFilter implements PrecFilterLink {
41  
42      private static Logger log = SCLogger.getLogger(DefaultLinkFilter.class);
43  
44      /***
45       *
46       * @param link
47       * @return
48       */
49      public boolean isPermitted(Context conf, Link link) {
50          log.debug("isPermitted() BEGIN");
51          String hostname = conf.getInitialLink().getHost();
52          boolean res = true;
53          if (hostname != null) {
54              res = link.toString().indexOf(hostname) >= 0;
55          }
56          log.debug("Checking link: " + link.toString()
57              + " VS " + hostname + " res="+res);
58          log.debug("isPermitted() END");
59          return res;
60      }
61  }